package com.android.mangalib.adapter;
import java.util.List;

import com.android.mangalib.activity.R;
import com.android.mangalib.object.Collection;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class CollectionAdapter extends BaseAdapter {

	List<Collection> library;
	LayoutInflater inflater;
	
	
	public CollectionAdapter(Context context, List<Collection> library) {
		inflater = LayoutInflater.from(context);
		this.library = library;
	}
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return library.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return library.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		CollectionViewHolder holder;
		
		if(convertView == null) {
			holder = new CollectionViewHolder();
			convertView = inflater.inflate(R.layout.itemcollection, null);
			holder.tvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
			holder.tvAuthor = (TextView)convertView.findViewById(R.id.tvAuthor);
			convertView.setTag(holder);
		}
		else {
			holder = (CollectionViewHolder)convertView.getTag();
		}
		
		holder.tvTitle.setText(library.get(position).getTitle());
		holder.tvAuthor.setText(library.get(position).getAuthor());
		
		return convertView;
	}
	
	public class CollectionViewHolder {
		
		public TextView tvTitle;
		public TextView tvAuthor;	
	}
	
	

}
